const {resolve} = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require("webpack")
const AddAssetHtmlWebpackPlugin = require("add-asset-html-webpack-plugin")

module.exports = {
     entry:"./src/js/index.js",
    output:{
        // [name] 入口文件名
        filename:"js/[name].[contenthash:10].js",
        path:resolve(__dirname,"build")
    },
    plugins:[ 
        //编译html
        new HtmlWebpackPlugin({
            filename:"index.html",
            template:"./src/index.html",
            minify:{
                collapseWhitespace:true,
                removeComments:true
            }
        }), 
        //添加manifest编译依赖
        new webpack.DllReferencePlugin({
            manifest: require('./dll/manifest.json')
        }),
        // 将某个文件打包输出，并在html中自动引入该资源
        new AddAssetHtmlWebpackPlugin({
            filepath:resolve(__dirname, 'dll/jquery.js')
        })

    ],
    mode:"production", 
    //externals 配置选项提供了「从输出的 bundle 中排除依赖」的方法
    externals:{
        jquery :"jquery"
    }
}